package com.itzz.spring_zhoneHeng.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itzz.spring_zhoneHeng.base.RestResponse;
import com.itzz.spring_zhoneHeng.dao.ModuleDao;
import com.itzz.spring_zhoneHeng.dao.RoleDao;
import com.itzz.spring_zhoneHeng.pojo.Module;
import com.itzz.spring_zhoneHeng.pojo.Role;
import com.itzz.spring_zhoneHeng.service.ModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service
public class ModuleServiceImpl implements ModuleService {
    @Autowired
    ModuleDao moduleDao;



    //查询所有  或 根据权姓名查询
    @Override
    public RestResponse queryAll(HashMap<String, Object> map) {


//        QueryWrapper<Module> moduleQueryWrapper = new QueryWrapper<>();
//        moduleQueryWrapper.eq(!map.get("roleName").equals(""),"role_name",map.get("roleName"));
//        List<Module> modules = moduleDao.selectList(null);
        //开启分页
        PageHelper.startPage((Integer) map.get("pageNum"),(Integer)map.get("pageSize"));
        //查询所有
        List<Module> modules = moduleDao.queryAll((String) map.get("roleName"));
        //添加到分页插件中
        PageInfo<Module> userPageInfo = new PageInfo<>(modules);
        return RestResponse.ok(userPageInfo);
    }

    //添加权限
    @Override
    public RestResponse add(Module module){
        int insert=0;
        if(module!=null&&!module.equals("")){
            module.setId(0);
            insert= moduleDao.insert(module);
        }
        return  RestResponse.ok(insert);
    }



}
